<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<html>
<head>
  <%@ include file="/common/meta.jsp" %>
  <title>所有流程（办理中）</title>

  <script type="text/javascript">
    var _path = "${_ctx}/flow/task";
    var _process = "${_ctx}/flow/process";
    $(function () {
      initLayout();
      $(window).resize(function () {
        initLayout();
      });

      $("#mainGrid").ligerGrid({
        columns: [
          {
            display: '序号',
            width: 40,
            render: function (rowData, rowindex, value, column, rowid, page, pageSize) {
              return (page - 1) * pageSize + rowindex + 1;
            }
          },
          {display: '业务名称', name: 'typeName', align: 'left', width: 120},
          {display: '工作说明', name: 'jobRemark', align: 'left', width: 120},
          {display: '提交时间', name: 'startDate', align: 'left', width: 140},
          {
            display: '操作', align: 'left', width: 220,
            render: function (item) {
              var result = "<a href=\"javascript:void(0)\" onclick=\"f_view('" + item.viewPageUrl + "')\">显示单据</a>";
              result += " <a href=\"javascript:void(0)\" onclick=\"f_status('" + item.instanceId + "')\">流程状态</a>";
              result += " <a href=\"javascript:void(0)\" onclick=\"f_picture('" + item.instanceId + "')\">流程图</a>";
              if(item.suspended)
                result += " <a href=\"javascript:void(0)\" onclick=\"f_activate('" + item.instanceId + "')\">激活</a>";
              else
                result += " <a href=\"javascript:void(0)\" onclick=\"f_suspend('" + item.instanceId + "')\">挂起</a>";
              result += " <a href=\"javascript:void(0)\" onclick=\"f_abort('" + item.instanceId + "')\">终止</a>";
              return result;
            }
          }
        ], sortName: "startDate", sortOrder: "desc", url: _path + "/getAllProcess?rnd=" + Math.random(),
        pageSize: 10,pageSizeOptions: [10,20,30,40],width: '100%', height: '100%', heightDiff: -1
      });
      $("#grid").height(document.documentElement.clientHeight - $(".toolbar").height());
    });

    function f_load() {
      $("#mainGrid").ligerGetGridManager().loadData(true);
    }

    function f_view(viewPageUrl) {
      window.open(viewPageUrl);
    }

    function f_status(instanceId) {
      var url;
      url = _path + "/dealHistoryList?instanceId="+instanceId;
      $.ligerDialog.open({
        title: '处理历史', width: 600, height: 500, allowClose: true, isResize: true, url: url
      });
    }

    function f_picture(instanceId) {
      window.open(_process + "/processViewBpmn?instanceId=" + instanceId);
    }

    function f_suspend(instanceId) {
      $.ajax({
        url: _process + "/suspendInstanceAdmin?instanceId="+instanceId,
        type: "POST", dataType: 'json',
        data: null,
        success: function (responseText) {
          BAP.closeWaitting();
          if (responseText.isError == false) {
            BAP.showSuccess("挂起成功!");
            f_load();
          } else {
            BAP.showError(responseText.msg);
          }
        },
        error: function () {
          BAP.closeWaitting();
          BAP.showError('挂起失败！');
        }
      });
    }

    function f_activate(instanceId) {
      $.ajax({
        url: _process + "/activateInstance?instanceId="+instanceId,
        type: "POST", dataType: 'json',
        data: null,
        success: function (responseText) {
          BAP.closeWaitting();
          if (responseText.isError == false) {
            BAP.showSuccess("激活成功!");
            f_load();
          } else {
            BAP.showError(responseText.msg);
          }
        },
        error: function () {
          BAP.closeWaitting();
          BAP.showError('激活失败！');
        }
      });
    }

    function f_abort(instanceId) {
      $.ajax({
        url: _process + "/stopInstanceAdmin?instanceId="+instanceId,
        type: "POST", dataType: 'json',
        data: null,
        success: function (responseText) {
          BAP.closeWaitting();
          if (responseText.isError == false) {
            BAP.showSuccess("终止成功!");
            f_load();
          } else {
            BAP.showError(responseText.msg);
          }
        },
        error: function () {
          BAP.closeWaitting();
          BAP.showError('终止失败！');
        }
      });
    }
  </script>
</head>

<body style="padding: 0;overflow:hidden;">
<%-- 工具栏 --%>
<div id="toolbar"></div>

<%-- 表格 --%>
<div id="grid">
  <div id="mainGrid" style="margin: -1px; min-width: 680px;"></div>
</div>
</body>
</html>
